"""
类创建层
"""
"学生，教师，管理员，课程，学校"
from db import db_handler
#父类，公共方法
class Base():
    @classmethod
    def self_select(cls,name):
        obj = db_handler.select_data(cls,name)
        # print(f"类{obj}")
        return obj  

    def self_save(self):
        db_handler.save_data(self)

#管理员类
class Admin(Base):
    def __init__(self,user_name,password):
        self.name = user_name
        self.password = password
    
    def create_school(self,name,addr):
        shcool_obj = School(name,addr)
        shcool_obj.self_save() 
          

    def create_crouse(self,crouse_name,crouse_price,crouse_week,school_obj):
        crouse_obj = Crouse(crouse_name,crouse_price,crouse_week)
        crouse_obj.self_save()
        school_obj.crouse.append(crouse_name)
        school_obj.self_save()

    def create_teather(self,teather_name,chushipassword):
        teather_obj = Teather(teather_name,chushipassword)
        teather_obj.self_save()

#学校类
class School(Base):
    def __init__(self,name,addr) -> None:
        self.name = name
        self.addr = addr
        self.crouse = []


#课程类
class Crouse(Base):
    def __init__(self,crouse_name,crouse_price,crouse_week) -> None:
        self.name = crouse_name
        self.pricr = crouse_price
        self.week = crouse_week
        self.student = []

#老师类
class Teather(Base):
    def __init__(self,teather_name,chushipassword):
            self.name = teather_name
            self.password = chushipassword
            self.crouse_list = []

    def check_crouse(self):
        return self.crouse_list

    def add_crouse(self,crouse_name):
        self.crouse_list.append(crouse_name)
        self.self_save()

    def get_student(self,crouse_name):
        crouse_obj = Crouse.self_select(crouse_name)
        return crouse_obj.student

    def change_sorce(self,student_name,sorce,crouse_name):
        student_obj = Student.self_select(student_name)
        student_obj.sorce[crouse_name] = sorce
        student_obj.self_save()
#学生类
class Student(Base):
    def __init__(self,student_name,student_password) -> None:
        self.name = student_name
        self.password = student_password
        self.school = None
        self.crouse_list = []
        self.sorce = {}

    def add_crouse(self,course_name):
        #学生绑定课程
        self.crouse_list.append(course_name)
        #设置课程分数默认为0
        self.sorce[course_name] = 0
        self.self_save()
        #课程绑定学生
        crouse_obj = Crouse.self_select(course_name)
        crouse_student_list = crouse_obj.student
        if self.name in  crouse_student_list:
            print("该课程已经添加此学生")
            pass
        crouse_obj.student.append(self.name)
        crouse_obj.self_save()



    def add_school(self,school_name):
        self.school = school_name
        self.self_save()